package chapter03;

/**
 * ClassName: Java08_Exception
 * Package: chapter03
 * DESCRIPTION:
 *
 * @Author 程翎钥
 * @Create 2024/4/14 17:10
 * @Version 1.0
 */
public class Java08_Exception {
    public static void main(String[] args) {
        // TODO 异常
        String account = "admin";
        String password = "admin";
        try {
            login(account,password);
        } catch (AccountException accountException) {
            System.out.println("账号");
        } catch (PasswordException passwordException) {
            System.out.println("密码");
        } catch (LoginException loginException) {
            System.out.println("其他");
        }
    }
    public static void login (String account,String password) {
        if(!"admin".equals(account)) {
            throw new AccountException("账号");
        }
        if(!"admin".equals(password)) {
            throw new PasswordException("密码");
        }
        System.out.println("correct");
    }
}
class AccountException extends LoginException{
    public AccountException(String message) {
        super(message);
    }
}
class PasswordException extends LoginException{
    public PasswordException(String message) {
        super(message);
    }
}
class LoginException extends RuntimeException{
    public LoginException(String message) {
        super(message);
    }
}